<%@ page language="java" contentType="text/html; charset=UTF-8"
	import="java.util.*" pageEncoding="UTF-8"%>
<%@page language="java" import="db_tool.DBConnection"%>
<%@page language="java" import="java.sql.ResultSet"%>
<%@page language="java" import="java.sql.Statement"%>

<%@page language="java" import="com.opensymphony.xwork2.ActionContext"%>
<%@page import="tree_util.Account"%>

<%
	List<String> user_power = (List<String>) session.getAttribute("userPower");
	//封装用户权限
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="edge" />
<meta name="author" content="Daliu" />
<meta name="keywords" content="长江上游珍稀特有鱼类保护信息管理系统、长江上游、珍稀特有鱼类、保护信息" />
<meta name="describe" content="长江上游珍稀特有鱼类保护信息管理系统" />
<title>长江上游珍稀特有鱼类保护信息管理系统</title>
<link href="css/register.css" rel="stylesheet" />
<link href="css/main.css" rel="stylesheet" />
<link href="css/show.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
<script type="text/javascript" src="js/showPhoto.js"></script>
</head>
<body>
	<div id="showAll" class="hideView">
		<div id="showPhoto" class="showphoto">
			<div class="container">
				<p id="modal-heading">
					<span class="title">查看上传照片</span> <span class="close closephoto">关闭</span>
				</p>
				<button id="last"
					style="cursor:pointer;display:block;float: left;width:50px;height:300px;border: 0px;background-color:transparent;">
					<span class="icon-circle-left" style="font-size: 40px;"></span>
				</button>
				<button id="next"
					style="cursor:pointer;width:50px;height: 300px;background-color:transparent;border: 0px;float: right;">
					<span class="icon-circle-right" style="font-size: 40px;"></span>
				</button>
				<div id="imgDiv"
					style="width:400px;height: 300px; display: block;float: left;">
					<img id="img1"
						style="width: 400px;height: 300px;border-radius:5px;"
						alt="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;没有照片！">
				</div>
			</div>
		</div>
	</div>
	<div>
		<h3 class="useractive check-h3">&nbsp;&nbsp;用户审核</h3>
		<div class="wrapper1">
			<table class="table thead">
				<tr>
					<th>#</th>
					<th>用户名</th>
					<th>电话</th>
					<th>邮箱</th>
					<th>状态</th>
					<th>单位</th>
					<th>通讯地址</th>
					<th>扫描件</th>
					<th>激活</th>
					<th>拒绝</th>
				</tr>
			</table>
			<table class="table tbody">
				<%
					String SuperiorName = ((Account) session.getAttribute("account")).getUsername();
					DBConnection db_connection = DBConnection.getInstance();
					Statement statement = null;
					statement = db_connection.getStatement();
					String sql = "select RegID,username,Telephone,Email,active,company,address,photo from RegisterAccount where active= 'no'";
					ResultSet resultSet = null;
					//System.out.println(sql);
					try {
						resultSet = statement.executeQuery(sql);
					} catch (Exception e) {
						e.printStackTrace();
					}
					boolean more = resultSet.next();
					if (!more) {
						out.print("没有用户需要激活");
					} else {
				%>
				<tr>
					<th>#</th>
					<th>用户名</th>
					<th>电话</th>
					<th>邮箱</th>
					<th>状态</th>
					<th>单位</th>
					<th>通讯地址</th>
					<th>扫描件</th>
					<th>激活</th>
					<th>拒绝</th>
				</tr>
				<%
					while (more) {
				%>
				<tr>
					<%
						for (int i = 1; i <= 7; i++) {
					%>
					<td><%=resultSet.getString(i)%></td>
					<%
						}
					%>
					<td><button class="btn btn-primary seeFile">查看</button></td>
					<td><button class="yes btn btn-primary">激活</button>
					</td>
					<td><button class="no btn btn-danger">拒绝</button>
					</td>
				</tr>
				<%
					more = resultSet.next();
						}
					}
					db_connection.close(resultSet, statement);
				%>
			</table>
		</div>

	</div>
	<script type="text/javascript">
		function suanxin() {
			location.reload([ true ]);
		}
		$().ready(function() {
			//滚动条宽度
			$(".thead").width($('.tbody').width());
			$(".thead").css("left", $('.wrapper1')[0].scrollWidth * 0.025);
			$(window).resize(function() {
				$(".thead").width($('.tbody').width());
				$(".thead").css("left", $('.wrapper1')[0].scrollWidth * 0.025);
			});
			//固定表头单元格宽度
			for (var i = 0; i < 9; i++) {
				$('.thead tr th:eq(' + i + ')').width($('.tbody tr th:eq(' + i + ')').width());
			}
			$(window).resize(function() {
				for (var i = 0; i < 9; i++) {
					$('.thead tr th:eq(' + i + ')').width($('.tbody tr th:eq(' + i + ')').width());
				}
			});
	
			//激活用户
			$(".yes").click(function() {
				var id = $(this).parent().siblings("td:eq(0)").text();
				var userName = $(this).parent().siblings("td:eq(1)").text();
				var email = $(this).parent().siblings("td:eq(3)").text();
				var thisTr = $(this).parent().parent();
				$.ajax({
					type : "post",
					async : false,
					url : "changeactive.action?ID=" + id,
					success : function(result) {
						if (result == "success") {
							alert("激活成功！");
							$.ajax({
								type : "post",
								async : false,
								url : "emailTip.action",
								data : {"Email" : email,
										"UserName" : userName}
							});
							thisTr.remove();
						} else {
							alert("激活失败，请重新激活！");
						}
					},
					error : function() {
						alert("激活失败，请重新激活！")
					}
				});
			});
			$(".no").click(function() {
				var id = $(this).parent().siblings("td:eq(0)").text();
				var thisTr = $(this).parent().parent();
				$.ajax({
					type : "post",
					async : false,
					url : "deleteactive.action?ID=" + id,
					success : function(result) {
						if (result == "success") {
							alert("已拒绝用户申请！");
							thisTr.remove();
						} else {
							alert("拒绝用户申请失败，请重新尝试！");
						}
					},
					error : function() {
						alert("拒绝用户申请失败，请重新尝试！")
					}
				});
			});
		});
	</script>
</body>
</html>